﻿/*
 * @author: wizardc
 */

using Dou.UI;
using TMPro.EditorUtilities;
using UnityEditor;
using UnityEngine;

namespace DouEditor.UI
{
    [CustomEditor(typeof(DTextMeshProUGUI), true)]
    public class DTextMeshProUGUIEditor : TMP_EditorPanelUI
    {
        [MenuItem("GameObject/DouUI/Text - TextMeshPro", false, 10)]
        private static void CreateUI(MenuCommand menuCommand)
        {
            var go = UIEditorUtil.CreateUIElement("Text (TMP)");
            var text = go.AddComponent<DTextMeshProUGUI>();
            text.text = "New Text";
            text.raycastTarget = false;
            text.richText = false;
            UIEditorUtil.PlaceUIElementRoot(go, menuCommand);
        }
        
        private SerializedProperty _onLink;
        
        protected override void OnEnable()
        {
            base.OnEnable();
            _onLink = serializedObject.FindProperty("_onLink");
        }

        public override void OnInspectorGUI()
        {
            var text = (DTextMeshProUGUI) target;
            using (new GUILayout.VerticalScope())
            {
                text.useGray = EditorGUILayout.Toggle(new GUIContent("置灰"), text.useGray);
                text.fontSetting = (FontSetting) EditorGUILayout.ObjectField(new GUIContent("字体设定"), text.fontSetting, typeof(FontSetting), false);
                text.faceColor = EditorGUILayout.ColorField(new GUIContent("主颜色"), text.faceColor);
                text.faceSoftness = EditorGUILayout.Slider(new GUIContent("柔软值"), text.faceSoftness, 0f, 1f);
                text.faceDilate = EditorGUILayout.Slider(new GUIContent("粗细值"), text.faceDilate, -1f, 1f);
                text.useOutLine = EditorGUILayout.Toggle(new GUIContent("启用描边"), text.useOutLine);
                text.outLineColor = EditorGUILayout.ColorField(new GUIContent("描边颜色"), text.outLineColor);
                text.outLineWidth = EditorGUILayout.Slider(new GUIContent("描边宽度"), text.outLineWidth, 0f, 1f);
            }
            base.OnInspectorGUI();
            serializedObject.Update();
            EditorGUILayout.PropertyField(_onLink);
            serializedObject.ApplyModifiedProperties();
        }
    }
}
